<?php

class model_firadio_php_sys_tablelist {

    public function __construct() {
        $db = db::getInstance();
        $this->firphp_tablelist = $db->table("firphp_tablelist tablelist LEFT JOIN firphp_menuclass menuclass ON menuclass.id=tablelist.menuclassid");
    }

    public function getProcTextByItemId($menuclassid) {
        //根据数据库的记录，生成程序代码的JSON数组
        $this->firphp_tablelist->field("menuclass.name,tablelist.id,tablelist.field,tablelist.defaorder,tablelist.numPerPage,tablelist.pageNumShown");
        $row = $this->firphp_tablelist->where("tablelist.menuclassid='{0}' AND menuclass.del_time='0'", array($menuclassid))->getone();
        $procs = array();
        if ($row) {
            $tablename = $row['name'];
            //$procs[] = array('typename' => 'classvar', 'note' => '要读的表名（先在common里定义好）', 'proctext' => array('classvar' => '$this->table', 'varname' => 'tablename', 'object' => "'{$row['tablename']}'"));
            $procs[] = array('id' => $row['id'], 'typename' => 'classvar', 'note' => '默认的排序', 'proctext' => array('classvar' => '$this->table', 'varname' => 'defaorder', 'object' => "'{$row['defaorder']}'"));
            $procs[] = array('id' => $row['id'], 'typename' => 'classvar', 'note' => '要读取的字段', 'proctext' => array('classvar' => '$this->table', 'varname' => 'field', 'object' => "'{$row['field']}'"));
            //$procs[] = array('id' => $row['id'], 'typename' => 'callclass', 'note' => '获取查询列表', 'proctext' => array('classvar' => '$this->table', 'function' => 'getList', 'assignvarname' => "\$this->tables['{$tablename}']"));
            $procs[] = array('id' => $row['id'], 'typename' => 'callclass', 'note' => '获取查询列表', 'proctext' => array('classvar' => '$this->table', 'function' => 'getList', 'assignvarname' => "\$this->tablelist"));
        }
        $return = json_encode($procs);
        return($return);
    }

    public function getProcTextByItemId_info($menuclassid) {
        //根据数据库的记录，生成程序代码的JSON数组
        $this->firphp_tablelist->field("menuclass.name,tablelist.id,tablelist.infofield");
        $row = $this->firphp_tablelist->where("tablelist.menuclassid='{0}' AND menuclass.del_time='0' AND tablelist.infofield<>''", array($menuclassid))->getone();
        $procs = array();
        if ($row) {
            $tablename = $row['name'];
            //$procs[] = array('typename' => 'classvar', 'note' => '要读的表名（先在common里定义好）', 'proctext' => array('classvar' => '$this->table', 'varname' => 'tablename', 'object' => "'{$row['tablename']}'"));
            $procs[] = array('id' => $row['id'], 'typename' => 'classvar', 'note' => '要读的条件', 'proctext' => array('classvar' => '$this->table', 'varname' => 'whereid', 'object' => "\$_GET['id']"));
            $procs[] = array('id' => $row['id'], 'typename' => 'classvar', 'note' => '要读取的字段', 'proctext' => array('classvar' => '$this->table', 'varname' => 'field', 'object' => "'{$row['infofield']}'"));
            //$procs[] = array('id' => $row['id'], 'typename' => 'callclass', 'note' => '获取查询列表', 'proctext' => array('classvar' => '$this->table', 'function' => 'getList', 'assignvarname' => "\$this->tables['{$tablename}']"));
            $procs[] = array('id' => $row['id'], 'typename' => 'callclass', 'note' => '获取查询列表', 'proctext' => array('classvar' => '$this->table', 'function' => 'getInfo', 'assignvarname' => "\$this->tableinfo"));
        }
        $return = json_encode($procs);
        return($return);
    }

}